Skip to content

Use _exit instead of exit in cmd__start_process when dup2 or execvp fails - #288

Open
angelcaru wants to merge 1 commit into
tsoding:mainfrom
angelcaru:main
Open

angelcaru wants to merge 1 commit into
tsoding:mainfrom
angelcaru:main

Conversation

@angelcaru

Copy link
Copy Markdown
Contributor

This prevents exit handlers from being run in these cases.
Example of code that would trigger the bug:

#define NOB_IMPLEMENTATION
#include "nob.h"

void cleanup(void) {
    nob_log(INFO, "Cleanup");
}

int main(void) {
    atexit(cleanup);
    Cmd cmd = {0};
    cmd_append(&cmd, "bogus-amogus");
    if (!cmd_run(&cmd)) return 1;
    return 0;
}

would output:

[INFO] CMD: bogus-amogus
[ERROR] Could not exec child process for bogus-amogus: No such file or directory
[INFO] Cleanup
[ERROR] command exited with exit code 1
[INFO] Cleanup

It now outputs:

[INFO] CMD: bogus-amogus
[ERROR] Could not exec child process for bogus-amogus: No such file or directory
[ERROR] command exited with exit code 1
[INFO] Cleanup

This prevents exit handlers from being run when execvp fails.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant